const { classesModel } = require('../models/classesModel');

module.exports.createClasses = async function (req, res) {
    try {
        const data = req.body;
        const result = await classesModel.create(data);
        console.log(data);
        if (result) {
            res.send({
                code: 1,
                massage: '班级数据新增成功',
                result
            })
        }
    } catch (error) {

        console.log('垃圾服务器');
        res.send({
            code: 0,
            massage: '班级数据新增失败',
            result
        })
    }
}

module.exports.getClasses = async function (req, res) {
    const result = await classesModel.find().populate('subjectsId');
    res.send({
        code: 1,
        massage: '班级数据获取成功',
        result
    })
}

module.exports.getClassesBySubjectsId = async (req, res) => {
   const data =  req.query;
   const result = await classesModel.find(data);
   res.send({
       code:1,
       message:'根据专业获取班级成功',
       result
   })
}